#!/usr/bin/perl
# wildre.pl
use warnings;
use strict;

$| = 1;   # enable autoflush for prompt display of prompt (sic)

print "Wildcard: ";
while (<>) {
   chomp;
   print "Regular Expression: ", wild2re($_), "\n";
   print "Wildcard: ";
}

sub wild2re {
   my $re = shift;
   $re =~ s/([^\w\s])/($1 eq '?')?'.'
   :($1 eq '*')?'.*'   :($1 eq '[' || $1 eq ']')?$1
   :"\\$1"/eg;
   return "^$re\$";   #anchor at both ends
}